#pragma once

#include <vector>
#include <string>

namespace kratos { namespace corelib {

struct StringUtil {
    // split string by any character in 'delim' and save sub-string to 'result'
    // @param src source string
    // @param delim delimeter
    // @param result sub-string result
    static void splitOf(const std::string& src, const std::string& delim, std::vector<std::string>& result);
    // split string by 'delim' and save sub-string to 'result'
    // @param src source string
    // @param delim delimeter
    // @param result sub-string result
    static void split(const std::string& src, const std::string& delim, std::vector<std::string>& result);
    // split string by 'delim' and save sub-string to 'result', the 'delim' will keep in result
    // @param src source string
    // @param delim delimeter
    // @param result sub-string result
    static void splitBy(const std::string& src, char delim, std::vector<std::string>& result);
    // Is 'src' end with 's'
    // @retval true
    // @retval false
    static bool endWith(const std::string& src, const std::string& s);
    // Is 'src' start with 's'
    // @retval true
    // @retval false
    static bool startWith(const std::string& src, const std::string& s);
    // erase sub-string 's' from 'src'
    // @param src source string
    // @param s target sub-string
    // @return new string
    static std::string remove(const std::string& src, const std::string& s);
    // erase character in 'delim' from 'src' at left side and right side
    // @param src source string
    // @param delim delimeter
    // @return new string
    static std::string trim(const std::string& src, const std::string& delim = " ");
    // erase character in 'delim' from 'src' at left side
    // @param src source string
    // @param delim delimeter
    // @return new string
    static std::string ltrim(const std::string& src, const std::string& delim = " ");
    // erase character in 'delim' from 'src' at right side
    // @param src source string
    // @param delim delimeter
    // @return new string
    static std::string rtrim(const std::string& src, const std::string& delim = " ");
    // replace 'pattern' in 'src' with 'dest'
    // @param src source string
    // @param pattern the sub-string needs replacing
    // @param dest replaced sub-string
    // @return new string
    static std::string replace(const std::string& src, const std::string& pattern, const std::string& dest);
    // returns file name but not include extension
    // eg. ab/c.txt -> c
    // @param src source string
    static std::string getFileName(const std::string& src);
    // Returns true if has the sub string
    static bool hasSubstring(const std::string& src, const std::string& sub);
};

}}
